
#include "DevModbusDeal.h"
#include "GDDevBase.h"
#include "ProtocolSwitch.h"
#include "DevRecode.h"


//档案
void Inv_agmtDeal()
{    
    memcpy(g_reg_bank[0].archive.manufacturer,manufactureritems[0],32);
    g_reg_bank[0].archive.devType=DEV_INV;
    g_reg_bank[0].archive.version = 7;

    for(int i=0;i<=max_num;i++)
	{
        if((i>=vol_a)&&(i<=runStatus_rd)) //读取的范围
        {
            YcItemg *newNode;
            newNode = (YcItemg *)malloc(sizeof(YcItemg));
            if (newNode == NULL) {
                printf("Memory allocation failed!\n");
                return ;
            }
            if (i == vol_a){
                g_reg_bank[0].regs[vol_a].flag=vaildFlag;
                g_reg_bank[0].regs[vol_a].type=type_u16;
                g_reg_bank[0].regs[vol_a].addr=5019;
                g_reg_bank[0].regs[vol_a].reg_count	=1;
                g_reg_bank[0].regs[vol_a].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
                g_reg_bank[0].regs[i].p=newNode;
            }
            else if(i==vol_b)
            {
                g_reg_bank[0].regs[vol_b].flag=vaildFlag;
                g_reg_bank[0].regs[vol_b].type=type_u16;
                g_reg_bank[0].regs[vol_b].addr=5020;
                g_reg_bank[0].regs[vol_b].reg_count=1;
                g_reg_bank[0].regs[vol_b].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==vol_c)
            {
                g_reg_bank[0].regs[vol_c].flag=vaildFlag;

                g_reg_bank[0].regs[vol_c].type=type_u16;
                g_reg_bank[0].regs[vol_c].addr=5021;
                g_reg_bank[0].regs[vol_c].reg_count=1;
                g_reg_bank[0].regs[vol_c].fc_rd =4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==cur_a)
            {
                g_reg_bank[0].regs[cur_a].flag=vaildFlag;
                g_reg_bank[0].regs[cur_a].type=type_u16;
                g_reg_bank[0].regs[cur_a].addr=5022;
                g_reg_bank[0].regs[cur_a].reg_count=1;
                g_reg_bank[0].regs[vol_a].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==cur_b)
            {
                g_reg_bank[0].regs[cur_b].flag=vaildFlag;

                g_reg_bank[0].regs[cur_b].type=type_u16;
                g_reg_bank[0].regs[cur_b].addr=5023;
                g_reg_bank[0].regs[cur_b].reg_count=1;
                g_reg_bank[0].regs[cur_b].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==cur_c)
            {
                g_reg_bank[0].regs[cur_c].flag=vaildFlag;

                g_reg_bank[0].regs[cur_c].type=type_u16;
                g_reg_bank[0].regs[cur_c].addr=5024;
                g_reg_bank[0].regs[cur_c].reg_count=1;
                g_reg_bank[0].regs[cur_c].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==p_a)
            {
                g_reg_bank[0].regs[p_a].flag=inValidFlag;

                g_reg_bank[0].regs[p_a].type=type_u32_cdab;
                g_reg_bank[0].regs[p_a].addr=5022;
                g_reg_bank[0].regs[p_a].reg_count=2;
                g_reg_bank[0].regs[p_a].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==p_b)
            {
                g_reg_bank[0].regs[p_b].flag=inValidFlag;

                g_reg_bank[0].regs[p_b].type=type_u32_cdab;
                g_reg_bank[0].regs[p_b].addr=5023;
                g_reg_bank[0].regs[p_b].reg_count=2;
                g_reg_bank[0].regs[p_b].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==p_c)
            {
                g_reg_bank[0].regs[p_c].flag=inValidFlag;

                g_reg_bank[0].regs[p_c].type=type_u32_cdab;
                g_reg_bank[0].regs[p_c].addr=5024;
                g_reg_bank[0].regs[p_c].reg_count=2;
                g_reg_bank[0].regs[p_c].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;

            }
            else if(i==p_all)
            {
                g_reg_bank[0].regs[p_all].flag=vaildFlag;

                g_reg_bank[0].regs[p_all].type=type_u32_cdab;
                g_reg_bank[0].regs[p_all].addr=5031;
                g_reg_bank[0].regs[p_all].reg_count=2;
                g_reg_bank[0].regs[p_all].fc_rd=4;
                newNode->mult=1;
                newNode->div =1;
            }
            else if(i==q_a)
            {
                g_reg_bank[0].regs[q_a].flag=vaildFlag;

                g_reg_bank[0].regs[q_a].type=type_u16;
                g_reg_bank[0].regs[q_a].addr=5022;
                g_reg_bank[0].regs[q_a].reg_count=1;
                g_reg_bank[0].regs[q_a].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==q_b)
            {
                g_reg_bank[0].regs[q_b].flag=inValidFlag;

                g_reg_bank[0].regs[q_b].type=type_u16;
                g_reg_bank[0].regs[q_b].addr=5023;
                g_reg_bank[0].regs[q_b].reg_count=1;
                g_reg_bank[0].regs[q_b].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==q_c)
            {
                g_reg_bank[0].regs[q_c].flag=inValidFlag;

                g_reg_bank[0].regs[q_c].type=type_u16;
                g_reg_bank[0].regs[q_c].addr=5033;
                g_reg_bank[0].regs[q_c].reg_count=1;
                g_reg_bank[0].regs[q_c].fc_rd=4;
                newNode->mult=1;
                newNode->div=10;
            }
            else if(i==q_all)
            {
                g_reg_bank[0].regs[q_all].flag=vaildFlag;
                g_reg_bank[0].regs[q_all].type=type_s32_cdab;
                g_reg_bank[0].regs[q_all].addr=5033;
                g_reg_bank[0].regs[q_all].reg_count=2;
                g_reg_bank[0].regs[q_all].fc_rd=4;
                newNode->mult=1;
                newNode->div =1;
            }
            else if(i==pf_a)
            {
                g_reg_bank[0].regs[pf_a].flag=inValidFlag;
                g_reg_bank[0].regs[pf_a].type=type_u16;
                g_reg_bank[0].regs[pf_a].addr=5022;
                g_reg_bank[0].regs[pf_a].reg_count=1;
                g_reg_bank[0].regs[pf_a].fc_rd=4;
                newNode->mult=1;
                newNode->div=1000;
            }
            else if(i==pf_b)
            {
                g_reg_bank[0].regs[pf_b].flag=inValidFlag;
                g_reg_bank[0].regs[pf_b].type=type_u16;
                g_reg_bank[0].regs[pf_b].addr=5023;
                g_reg_bank[0].regs[pf_b].reg_count=1;
                g_reg_bank[0].regs[pf_b].fc_rd=4;
                newNode->mult=1;
                newNode->div=1000;
            }
            else if(i==pf_c)
            {
                g_reg_bank[0].regs[pf_c].flag=inValidFlag;

                g_reg_bank[0].regs[pf_c].type=type_u16;
                g_reg_bank[0].regs[pf_c].addr=5019;
                g_reg_bank[0].regs[pf_c].reg_count=1;
                g_reg_bank[0].regs[pf_c].fc_rd=4;
                newNode->mult=1;
                newNode->div=1000;
            }
            else if(i==pf_all)
            {
                g_reg_bank[0].regs[pf_all].flag=vaildFlag;

                g_reg_bank[0].regs[pf_all].type=type_s16;
                g_reg_bank[0].regs[pf_all].addr=5035;
                g_reg_bank[0].regs[pf_all].reg_count=1;
                g_reg_bank[0].regs[pf_all].fc_rd=4;
                newNode->mult=1;
                newNode->div=1000;
            }
            else if(i==rated_p)
            {
                g_reg_bank[0].regs[rated_p].flag=vaildFlag;
                g_reg_bank[0].regs[rated_p].type=type_u16;
                g_reg_bank[0].regs[rated_p].addr=5001;
                g_reg_bank[0].regs[rated_p].reg_count=1;
                g_reg_bank[0].regs[rated_p].fc_rd=4;
                newNode->mult=100;
                newNode->div=1;
            }
            else if(i==rated_q)
            {
                g_reg_bank[0].regs[rated_q].flag=vaildFlag;

                g_reg_bank[0].regs[rated_q].type=type_u16;
                g_reg_bank[0].regs[rated_q].addr=5049;
                g_reg_bank[0].regs[rated_q].reg_count=1;
                g_reg_bank[0].regs[rated_q].fc_rd=4;
                newNode->mult=100;
                newNode->div=1;
            }
            else if(i==deg)
            {
                g_reg_bank[0].regs[deg].flag=vaildFlag;

                g_reg_bank[0].regs[deg].type=type_u16;
                g_reg_bank[0].regs[deg].addr=5003;
                g_reg_bank[0].regs[deg].reg_count=1;
                g_reg_bank[0].regs[deg].fc_rd=04;
                newNode->mult=1;
                newNode->div=10;
            }
            g_reg_bank[0].regs[i].p=newNode;
        }
				
        if(i==runStatus_rd)
        {
            Yk_TurnItemg *newYk_turn;
            newYk_turn = (Yk_TurnItemg *)malloc(sizeof(Yk_TurnItemg));

            if(i==runStatus_rd)
            {
                g_reg_bank[0].regs[runStatus_rd].flag=vaildFlag;

                g_reg_bank[0].regs[runStatus_rd].type=type_u16;
                g_reg_bank[0].regs[runStatus_rd].addr=5006;
                g_reg_bank[0].regs[runStatus_rd].reg_count=1;
                g_reg_bank[0].regs[runStatus_rd].fc_rd=04;
                newYk_turn->val_on =0xcf;
                newYk_turn->val_off=0xce;
            }
            g_reg_bank[0].regs[i].p=newYk_turn;
        }

        if(i==outType)
        {
            OutTypeg *newOutType;
            newOutType = (OutTypeg *)malloc(sizeof(OutTypeg));
            g_reg_bank[0].regs[outType].flag=vaildFlag;
            g_reg_bank[0].regs[outType].type=type_u16;
            g_reg_bank[0].regs[outType].addr=5002;
            g_reg_bank[0].regs[outType].reg_count=1;
            g_reg_bank[0].regs[outType].fc_rd=4;
            newOutType->val_single=0;
            newOutType->val_3_phase_3_wire=2;
            newOutType->val_3_phase_4_wire=1;
            newOutType->def_type=0;
            g_reg_bank[0].regs[i].p=newOutType;
        }

        //p
        if(i==runStatus_wr_open)
        {
            YkItemg *newYk;
            newYk = (YkItemg *)malloc(sizeof(YkItemg));
            if (newYk == NULL)
            {
                printf("Memory allocation failed!\n");
                return ;
            }
            g_reg_bank[0].regs[runStatus_wr_open].flag=vaildFlag;

            g_reg_bank[0].regs[runStatus_wr_open].type=type_u16;
            g_reg_bank[0].regs[runStatus_wr_open].addr=5006;
            g_reg_bank[0].regs[runStatus_wr_open].reg_count=1;
            g_reg_bank[0].regs[runStatus_wr_open].fc_rd=06;
            newYk->val_data=0xcf;
            g_reg_bank[0].regs[i].p=newYk;
        }
        else if(i==runStatus_wr_close)
        {
            YkItemg *newYk;
            newYk = (YkItemg *)malloc(sizeof(YkItemg));
            if (newYk == NULL)
            {
                printf("Memory allocation failed!\n");
                return ;
            }
            g_reg_bank[0].regs[runStatus_wr_close].flag=vaildFlag;

            g_reg_bank[0].regs[runStatus_wr_close].type=type_u16;
            g_reg_bank[0].regs[runStatus_wr_close].addr=5006;
            g_reg_bank[0].regs[runStatus_wr_close].reg_count=1;
            g_reg_bank[0].regs[runStatus_wr_close].fc_rd=06;
            newYk->val_data=0xce;
            g_reg_bank[0].regs[i].p=newYk;
        }

			
        if(i>=p_set_model&&i<=p_set_num)//&&(i<=runStatus_rd))//遥控的范围
        {
            if(i==p_set_model)
            {
                YkItemg *newYk;
                newYk = (YkItemg *)malloc(sizeof(YkItemg));
                if (newYk == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[p_set_model].flag=vaildFlag;
                g_reg_bank[0].regs[p_set_model].type=type_u16;
                g_reg_bank[0].regs[p_set_model].addr=5007;
                g_reg_bank[0].regs[p_set_model].reg_count=1;
                g_reg_bank[0].regs[p_set_model].fc_wr=06;
                newYk->val_data=0xaa;
                g_reg_bank[0].regs[i].p=newYk;
            }
            else if(i==p_set_num)
            {
                YtItemg_pct *newYt;
                newYt = (YtItemg_pct *)malloc(sizeof(YtItemg_pct));
                if (newYt == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[p_set_num].flag=vaildFlag;
                g_reg_bank[0].regs[p_set_num].type=type_u16;
                g_reg_bank[0].regs[p_set_num].addr=5039;
                g_reg_bank[0].regs[p_set_num].reg_count=1;
                g_reg_bank[0].regs[p_set_num].fc_wr=06;
                newYt->mult=100;
                newYt->div=1;
                newYt->funtion=data_ctr;
                g_reg_bank[0].regs[i].p=newYt;
            }
        }

        //q
        if(i>=q_set_model&&i<=q_set_num)//&&(i<=runStatus_rd))//遥控的范围
        {

            if(i==q_set_model)
            {
                YkItemg *newYk;
                newYk = (YkItemg *)malloc(sizeof(YkItemg));
                if (newYk == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[q_set_model].flag=vaildFlag;
                g_reg_bank[0].regs[q_set_model].type=type_u16;
                g_reg_bank[0].regs[q_set_model].addr=5036;
                g_reg_bank[0].regs[q_set_model].reg_count=1;
                g_reg_bank[0].regs[q_set_model].fc_wr=06;
                newYk->val_data=0xa2;
                g_reg_bank[0].regs[i].p=newYk;
            }
            else if(i==q_set_num)
            {
                YtItemg_pct *newYt;
                newYt = (YtItemg_pct *)malloc(sizeof(YtItemg_pct));
                if (newYt == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[q_set_num].flag=vaildFlag;
                g_reg_bank[0].regs[q_set_num].type=type_u16;
                g_reg_bank[0].regs[q_set_num].addr=5040;
                g_reg_bank[0].regs[q_set_num].reg_count=1;
                g_reg_bank[0].regs[q_set_num].fc_wr=06;
                newYt->mult=100;
                newYt->div=1;
                newYt->funtion=data_ctr;
                g_reg_bank[0].regs[i].p=newYt;
            }
        }

        //pf
        if(i>=pf_set_model&&i<=pf_set_num)//&&(i<=runStatus_rd))//遥控的范围
        {

            if(i==pf_set_model)
            {
                YkItemg *newYk;
                newYk = (YkItemg *)malloc(sizeof(YkItemg));
                if (newYk == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[pf_set_model].flag=vaildFlag;
                g_reg_bank[0].regs[pf_set_model].type=type_u16;
                g_reg_bank[0].regs[pf_set_model].addr=5036;
                g_reg_bank[0].regs[pf_set_model].reg_count=1;
                g_reg_bank[0].regs[pf_set_model].fc_wr=06;
                newYk->val_data=0xa1;
                g_reg_bank[0].regs[i].p=newYk;
            }
            else if(i==pf_set_num)
            {
                YtItemg *newYt;
                newYt = (YtItemg *)malloc(sizeof(YtItemg));
                if (newYt == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[pf_set_num].flag=vaildFlag;
                g_reg_bank[0].regs[pf_set_num].type=type_u16;
                g_reg_bank[0].regs[pf_set_num].addr=5019;
                g_reg_bank[0].regs[pf_set_num].reg_count=1;
                g_reg_bank[0].regs[pf_set_num].fc_wr=06;
                newYt->mult=1;
                newYt->div=1000;
                g_reg_bank[0].regs[i].p=newYt;
            }
        }

        //p_pct
        if(i>=p_pct_set_model&&i<=p_pct_set_num)//&&(i<=runStatus_rd))//遥控的范围
        {

            if(i==p_pct_set_model)
            {
                YkItemg *newYk;
                newYk = (YkItemg *)malloc(sizeof(YkItemg));
                if (newYk == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[p_pct_set_model].flag=vaildFlag;

                g_reg_bank[0].regs[p_pct_set_model].type=type_u16;
                g_reg_bank[0].regs[p_pct_set_model].addr=5007;
                g_reg_bank[0].regs[p_pct_set_model].reg_count=1;
                g_reg_bank[0].regs[p_pct_set_model].fc_wr=06;
                newYk->val_data=0xaa;
                g_reg_bank[0].regs[i].p=newYk;
            }
            else if(i==p_pct_set_num)
            {
                YtItemg_pct *newYt_pct;
                newYt_pct = (YtItemg_pct *)malloc(sizeof(YtItemg_pct));
                if (newYt_pct == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[p_pct_set_num].flag=vaildFlag;

                g_reg_bank[0].regs[p_pct_set_num].type=type_s16;//type_u16
                g_reg_bank[0].regs[p_pct_set_num].addr=5008;
                g_reg_bank[0].regs[p_pct_set_num].reg_count=1;
                g_reg_bank[0].regs[p_pct_set_num].fc_wr=06;
                newYt_pct->mult=1;
                newYt_pct->div=10;
                newYt_pct->funtion=pct_ctr;
                g_reg_bank[0].regs[i].p=newYt_pct;
            }
        }

        //q_pct
        if(i>=q_pct_set_model&&i<=q_pct_set_num)//&&(i<=runStatus_rd))//遥控的范围
        {

            if(i==q_pct_set_model)
            {
                YkItemg *newYk;
                newYk = (YkItemg *)malloc(sizeof(YkItemg));
                if (newYk == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[q_pct_set_model].flag=vaildFlag;
                g_reg_bank[0].regs[q_pct_set_model].type=type_u16;
                g_reg_bank[0].regs[q_pct_set_model].addr=5036;
                g_reg_bank[0].regs[q_pct_set_model].reg_count=1;
                g_reg_bank[0].regs[q_pct_set_model].fc_wr=06;
                newYk->val_data=0xa2;
                g_reg_bank[0].regs[i].p=newYk;
            }
            else if(i==q_pct_set_num)
            {
                YtItemg_pct *newYt_pct;
                newYt_pct = (YtItemg_pct *)malloc(sizeof(YtItemg_pct));
                if (newYt_pct == NULL)
                {
                    printf("Memory allocation failed!\n");
                    return ;
                }
                g_reg_bank[0].regs[q_pct_set_num].flag=vaildFlag;
                g_reg_bank[0].regs[q_pct_set_num].type=type_s16;
                g_reg_bank[0].regs[q_pct_set_num].addr=5037;
                g_reg_bank[0].regs[q_pct_set_num].reg_count=1;
                g_reg_bank[0].regs[q_pct_set_num].fc_wr=06;
                newYt_pct->mult=1;
                newYt_pct->div=10;
                newYt_pct->funtion=pct_ctr;
                g_reg_bank[0].regs[i].p=newYt_pct;
            }
        }
	}

 }
